import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 根本数据  被数据库解析后得到， 用于生成java 文件 dao 文件 mapper.xml 文件
 * 2018年7月5日
 * @author ye.yangyang
 */
public class BaseData {
	
	public BaseData(String dataBase,String tableName) {
		this.tableName = tableName;
		this.dataBase = dataBase;
		this.className = JavaTool.mysqlTableTurnToJavaClass(tableName);
		this.baseDataPropertys = initProp();
	}
	
	/**
	 * 从表中初始化属性值
	 * @author ye.yangyang
	 * 2018年7月11日
	 * @param tableName
	 * @return
	 */
	private List<BaseDataProperty> initProp() {
		List<BaseDataProperty> bdps = new ArrayList<BaseDataProperty>();
		JDBC jdbc = new JDBC(dataBase);
		List<Map<String,String>> list = jdbc.getColRet(tableName);
		jdbc.close();
		for (Map<String,String> resultSet : list) {
			String type = resultSet.get(JDBC.COL_TYPE);
			String name = resultSet.get(JDBC.COL_NAME);
			String notes = resultSet.get(JDBC.COL_COMMENT);
			String javaName = JavaTool.mysqlColNameTurnToJavaProName(name);
			BaseDataProperty bdp = new BaseDataProperty(type, name, notes,javaName);
			bdps.add(bdp);
		}
		return bdps;
	}
	private String dataBase;
	private String tableName;
	private String className;
	private List<BaseDataProperty>  baseDataPropertys;
	public String getClassName() {
		return className;
	}
	public void setClassName(String className) {
		this.className = className;
	}
	public List<BaseDataProperty> getBaseDataPropertys() {
		return baseDataPropertys;
	}
	public void setBaseDataPropertys(List<BaseDataProperty> baseDataPropertys) {
		this.baseDataPropertys = baseDataPropertys;
	}
	public String getDataBase() {
		return dataBase;
	}
	public void setDataBase(String dataBase) {
		this.dataBase = dataBase;
	}
	public String getTableName() {
		return tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
}
/**
 * 根本数据的属性
 * 2018年7月5日
 * @author ye.yangyang
 */
class BaseDataProperty{
	private String type;
	private String name;
	private String javaName;
	private String range;
	private String pk;
	private String notes;

	public BaseDataProperty(String type, String name, String notes) {
		super();
		this.type = type;
		this.name = name;
		this.notes = notes;
	}

	public BaseDataProperty(String type, String name, String notes,String javaName) {
		super();
		this.type = type;
		this.name = name;
		this.notes = notes;
		this.javaName = javaName;
	}
	
	public BaseDataProperty(String type, String name, String range, String pk,String notes) {
		super();
		this.type = type;
		this.name = name;
		this.range = range;
		this.pk = pk;
		this.notes = notes;
	}
	
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getRange() {
		return range;
	}
	public void setRange(String range) {
		this.range = range;
	}
	public String getPk() {
		return pk;
	}
	public void setPk(String pk) {
		this.pk = pk;
	}
	public String getNotes() {
		return notes;
	}
	public void setNotes(String notes) {
		this.notes = notes;
	}
	public String getJavaName() {
		return javaName;
	}
	public void setJavaName(String javaName) {
		this.javaName = javaName;
	}
	
}
